window.vm = new Vue({
    el: '#app',
    data: {

        //评分
        oneNo:'',
        //评分
        rate: null,
        text:['非常不满意','不满意','一般','满意','非常满意'],
        rateRemark: '',

        onePro:'',
        //完成时备注
        remark: '',
        workHours: '',
        // activeName: 'second',
        // accepted: 0
        file: [],


        drawer: false,
        user: {
            name: '',
        },
        user1: '',
        post:'',
        //获取下一个审批的信息
        approve:'',
        //获取第一个审批信息
        approve1:'',
        //获取第二个审批信息
        approve2:'',
        //获取第三个审批信息
        approve3:'',

        rules: {
            value2: [
                { required: true, message: '请选择时间', trigger: 'blur' },
            ],
            // workHours: [
            //     { required: true, type: 'number',message: '请输入工时', trigger: 'blur' },
            // ],
        },

        pickerOptions: {
            shortcuts: [{
                text: '今天',
                onClick(picker) {
                    const now = new Date();
                    const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
                    picker.$emit('pick', new Date(today.getTime() + 24 * 60 * 60 * 1000 - 1));
                }
            }, {
                text: '四小时',
                onClick(picker) {
                    const date = new Date();
                    date.setTime(date.getTime() + 3600 * 1000 * 4);
                    picker.$emit('pick', date);
                }
            }, {
                text: '明天',
                onClick(picker) {
                    const date = new Date();
                    date.setTime(date.getTime() + 3600 * 1000 * 24 );
                    picker.$emit('pick', date);
                }
            }]
        },
        value2: '',



    },
    methods: {


        handleChange(file, fileList) {
            this.file = fileList.slice(-3);
        },

        back:function (){
            top.location.href = "enProcess.html"
        },

        deskBack:function (){
            top.location.href = "index.html"
        },

        //审批通过
        pass:function (){
            this.$confirm('确认审批', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '审批通过!'
                });
                if(vm.onePro.fileList)
                    vm.onePro.fileList = vm.onePro.fileList.join(', ')
                vm.approve.status = 1
                axios({
                    method: 'post',
                    url: '/updateApprove',
                    headers:{
                        'Context-Type': 'application/json' //
                    },
                    data: this.approve//
                }).then(() => {
                    // console.log(vm.approve)
                    // setTimeout(function () {
                    // top.location.href = "index.html"
                    location.reload();
                    // }, 500);
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消!'
                });
            });

        },


        //审批退回
        goBack:function (){
            this.$confirm('确认退回', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '工单已退回!'
                });
                if(vm.onePro.fileList)
                    vm.onePro.fileList = vm.onePro.fileList.join(', ')
                vm.approve.status = 2
                axios({
                    method: 'post',
                    url: '/updateApprove',
                    headers:{
                        'Context-Type': 'application/json' // 1
                    },
                    data: this.approve// 2
                }).then(() => {
                    setTimeout(function () {
                        top.location.href = "index.html"
                    }, 500);
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消!'
                });
            });

        },

        //判断是否有完成时间
        dispatch:function (){
            if(!vm.value2){
                alert("请选择完成时间")
            }else{
                vm.drawer = true
            }
        },

        //选择工程师
        selectEn:function (row, event, column) {
            this.$confirm('你确认派给\'' + row.name + '\'?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '派单成功!'
                });
                if(vm.onePro.fileList)
                    vm.onePro.fileList = vm.onePro.fileList.join(', ')
                vm.onePro.respaName = row.name
                vm.onePro.etime = vm.value2
                vm.onePro.state = 1
                axios({
                    method: 'post',
                    url: '/updateProcess',
                    headers: {
                        'Context-Type': 'application/json' // 1
                    },
                    data: this.onePro// 2
                }).then(() => {
                    setTimeout(function () {
                        top.location.href = "desk.html"
                    }, 500);
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消派单'
                });
            });
        },

        //转给其他工程师
        changeEn:function (row, event, column){
            this.$confirm('你确认转派给\''+row.name+'\'?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '转派成功!'
                });
                if(vm.onePro.fileList)
                    vm.onePro.fileList = vm.onePro.fileList.join(', ')
                vm.onePro.respaName = row.name
                axios({
                    method: 'post',
                    url: '/updateProcess',
                    headers:{
                        'Context-Type': 'application/json' // 1
                    },
                    data: this.onePro// 2
                }).then(() => {
                    setTimeout(function () {
                        top.location.href = "enProcess.html"
                    }, 500);
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消转派'
                });
            });


        },

        //接单
        accepted:function(){
            this.$confirm('确认接单', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '接单成功!'
                });
                if(vm.onePro.fileList)
                    vm.onePro.fileList = vm.onePro.fileList.join(', ')
                vm.onePro.isAccepted = 1
                axios({
                    method: 'post',
                    url: '/updateProcess',
                    headers:{
                        'Context-Type': 'application/json' // 1
                    },
                    data: this.onePro// 2
                }).then((res) => {
                    top.location.href = "enProcess.html"
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消接单!'
                });
            });
        },


        //结束工单
        submitOnePro:function (){

            if(!vm.workHours){
                alert("请输入工时")
                return
            }
            this.$confirm('确认结束', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '工单已结束!'
                });
                if(vm.onePro.fileList)
                    vm.onePro.fileList = vm.onePro.fileList.join(', ')
                vm.onePro.remark = vm.remark
                vm.onePro.workHours = vm.workHours
                vm.onePro.state = 2
                axios({
                    method: 'post',
                    url: '/updateProcess',
                    headers:{
                        'Context-Type': 'application/json' // 1
                    },
                    data: this.onePro// 2
                }).then((res) => {
                    top.location.href = "enProcess.html"
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消!'
                });
            });
        },

        changeValue:function (value){
            vm.rate = value
            // vm.onePro.score = value
        },

        submitScore:function (){
            vm.onePro.itScore = vm.rate
            vm.onePro.itRemark = vm.rateRemark
            if(vm.onePro.fileList)
                vm.onePro.fileList = vm.onePro.fileList.join(', ')

            axios({
                method: 'post',
                url: '/updateProcess',
                headers:{
                    'Context-Type': 'application/json' // 1
                },
                data: this.onePro// 2
            }).then((res) => {
                alert("服务单评价成功")
                // top.location.href = "userProcess.html"
            });

        },

        //改变审批流程图标
        geticon(value) {
            let icon = ''
            if (value==1) {
                icon = 'el-icon-check'
            }else if(value==2){
                icon = 'el-icon-close'
            } else {
                icon = ''
            }
            return icon
        },




    },



    created: function () {
        // let processNo = JSON.parse(sessionStorage.getItem("processNo"));
        let params = new URLSearchParams(window.location.search);
        let processNo
        if(params.get("processNo"))
            processNo = JSON.parse(params.get("processNo"))
         else
            processNo = JSON.parse(sessionStorage.getItem("processNo"))


        //获取工单信息
        axios.get(
            "/getPro",{
                params: {
                    processNo: processNo
                }
            }
        ).then(function (res) {
            vm.onePro = res.data
            if(vm.onePro.fileList)
                vm.onePro.fileList = vm.onePro.fileList.split(", ")
        }).catch(e => {
            ajaxError(vm, e);
        });

        //获取审批信息
        axios.get(
            "/getApprove",{
                params: {
                    processNo: processNo
                }
            }
        ).then(function (res) {
            vm.approve = res.data
        }).catch(e => {
            ajaxError(vm, e);
        });

        //获取第一个审批
        axios.get(
            "/approve1",{
                params: {
                    processNo: processNo
                }
            }
        ).then(function (res) {
            vm.approve1 = res.data
        }).catch(e => {
            ajaxError(vm, e);
        });

        //获取第二个审批
        axios.get(
            "/approve2",{
                params: {
                    processNo: processNo
                }
            }
        ).then(function (res) {
            vm.approve2 = res.data
        }).catch(e => {
            ajaxError(vm, e);
        });

        //获取第三个审批
        axios.get(
            "/approve3",{
                params: {
                    processNo: processNo
                }
            }
        ).then(function (res) {
            vm.approve3 = res.data
        }).catch(e => {
            ajaxError(vm, e);
        });

        //获取工程师姓名(用来做指派)
        axios.get(
            "/getEnName",
        ).then(function (res) {
            vm.user=res.data
        }).catch(e => {
            ajaxError(vm, e);
        });

        //获取本人信息
        axios.get(
            "/getUser",
        ).then(function (res) {
            vm.user1=res.data
        }).catch(e => {
            ajaxError(vm, e);
        });


    },
});


